package com.wuyou.designPatterns.visiotor;

import net.sf.jsqlparser.expression.operators.arithmetic.Division;

import java.util.Iterator;

/**
 * @Description
 * @Author 无忧
 * @Date 2024/10/11 21:25
 */
public class ListVisitor extends Visitor {
    private String currentDir = "";


    @Override
    public void visit(File file) {
        System.out.println(currentDir + "/" + file);
    }

    @Override
    public void visit(Directory directory) {
        System.out.println(currentDir + "/" + directory);
        String saveDir = currentDir;
        currentDir = currentDir + "/" + directory.getName();
        Iterator<Entry> iterator = directory.iterator();
        while (iterator.hasNext()){
            Entry entry = iterator.next();
            entry.accept(this);
        }
        currentDir = saveDir;
    }
}
